package me.jollyfly.jshop.web.portal.service

import me.jollyfly.jshop.common.bean.ResultBean
import me.jollyfly.jshop.user.client.api.UserApi
import me.jollyfly.jshop.user.client.model.dto.LoginUserDTO
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

/**
 *  created at 2018/1/25
 *  @author 354649
 *
 */
interface LoginAndRegisterService {

    fun login(loginUserDTO: LoginUserDTO): LoginResult
}


@Service
open class LoginAndRegisterServiceImpl : LoginAndRegisterService {

    @Autowired
    private var userApi: UserApi? = null

    override fun login(loginUserDTO: LoginUserDTO): LoginResult {
        val resultBean = this.userApi!!.login(loginUserDTO)
        if (resultBean.code == ResultBean.SUCCESS) {
            return LoginResult(true, resultBean.msg, resultBean.data!!)
        }
        return LoginResult(false, resultBean.msg, "");
    }
}

class LoginResult constructor() {

    var loginSuccess: Boolean = false

    var msg: String = ""

    var token: String = ""

    constructor(loginSuccess: Boolean, msg: String, token: String) : this() {
        this.loginSuccess = loginSuccess
        this.msg = msg
        this.token = token
    }
}